package cn.cms.chuangjia.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import cn.cms.chuangjia.domain.Msg;
import cn.cms.chuangjia.vo.AjaxResult;
import cn.cms.chuangjia.vo.Page;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
//import com.ruoyi.common.annotation.Log;
//import com.ruoyi.common.core.controller.BaseController;
//import com.ruoyi.common.core.domain.AjaxResult;
//import com.ruoyi.common.enums.BusinessType;
import cn.cms.chuangjia.service.IMsgService;


/**
 * 留言Controller
 * 
 * @author ruoyi
 * @date 2024-01-18
 */
@RestController
@RequestMapping("/cms/msg")
public class MsgController extends BaseController
{
    @Autowired
    private IMsgService msgService;

    /**
     * 查询留言列表
     */
    //@PreAuthorize("@ss.hasPermi('msg:msg:list')")
    @GetMapping("/list")
    public Page<Msg> list(Msg msg)
    {
        startPage();
        List<Msg> list = msgService.selectMsgList(msg);
        return Page.convert(PageInfo.of(list));
    }

    /**
     * 导出留言列表
     */
   // @PreAuthorize("@ss.hasPermi('msg:msg:export')")
    //@Log(title = "留言", businessType = BusinessType.EXPORT)
//    @PostMapping("/export")
//    public void export(HttpServletResponse response, Msg msg)
//    {
//        List<Msg> list = msgService.selectMsgList(msg);
//        ExcelUtil<Msg> util = new ExcelUtil<Msg>(Msg.class);
//        util.exportExcel(response, list, "留言数据");
//    }

    /**
     * 获取留言详细信息
     */
    //@PreAuthorize("@ss.hasPermi('msg:msg:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(msgService.selectMsgById(id));
    }

    /**
     * 新增留言
     */
    //@PreAuthorize("@ss.hasPermi('msg:msg:add')")
    //@Log(title = "留言", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Msg msg)
    {
        return AjaxResult.toAjax(msgService.insertMsg(msg));
    }

    /**
     * 修改留言
     */
    //@PreAuthorize("@ss.hasPermi('msg:msg:edit')")
   // @Log(title = "留言", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Msg msg)
    {
        return AjaxResult.toAjax(msgService.updateMsg(msg));
    }

    /**
     * 删除留言
     */
    //@PreAuthorize("@ss.hasPermi('msg:msg:remove')")
   // @Log(title = "留言", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return AjaxResult.toAjax(msgService.deleteMsgByIds(ids));
    }
}
